function exportFigure(fhandle, format, fileName, paperPosition)

% validate arguments
if (nargin == 3)
    paperPosition = [1 0 28.5 21];
end

failIfFalse(isvector(paperPosition), 'paperPosition should be a vector');
failIfFalse(ischar(format), 'format should be a string');
failIfFalse(isvector(fileName), 'fileName should be a string');

% set figure properties
set(fhandle(), 'PaperPositionMode', 'manual');
set(fhandle(), 'PaperOrientation', 'landscape');
set(fhandle(), 'PaperUnits', 'centimeters');
set(fhandle(), 'PaperType', 'A4');
set(fhandle(), 'PaperPosition', paperPosition);

% export graph
if(strcmp(format, 'ps'))    
    print('-noui', '-dpsc2', fileName);
elseif (strcmp(format, 'eps'))    
    print('-noui', '-depsc2', fileName);
elseif (strcmp(format, 'png'))
		set(fhandle(), 'PaperOrientation', 'portrait');
    print('-noui', '-dpng', fileName);
else
    error(strcat('Unexpected format: ', format));
end
    
    